package com.cyq.day21.managementsystem;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.time.LocalDate;

public class OrderManagement extends JFrame {
    private JLabel label1, label2, label3;
    private JTextField textField1, textField2, textField3;
    private JButton button1, button2;
    private JPanel panel1, panel2, panel3, panel4;

    public OrderManagement(Order[] orders) {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle("入库");
        setLayout(new GridLayout(4, 1, 5, 5));
        label1 = new JLabel();
        label1.setText("取货码");
        textField1 = new JTextField(20);
        panel1 = new JPanel();
        panel1.add(label1);
        panel1.add(textField1);
        //
        label2 = new JLabel();
        label2.setText("收货人");
        textField2 = new JTextField(20);
        panel2 = new JPanel();
        panel2.add(label2);
        panel2.add(textField2);
        //
        label3 = new JLabel();
        label3.setText("收货人电话");
        textField3 = new JTextField(20);
        panel3 = new JPanel();
        panel3.add(label3);
        panel3.add(textField3);
        //
        button1 = new JButton("确定");
        button2 = new JButton("取消");
        panel4 = new JPanel();
        panel4.add(button1);
        panel4.add(button2);
        this.add(panel1);
        this.add(panel2);
        this.add(panel3);
        this.add(panel4);
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String inputNum = textField1.getText();
                String inputPeople = textField2.getText();
                String inputTel = textField3.getText();
                for (int i = 0; i < orders.length; i++) {
                    if (orders[i] == null) {
                        orders[i] = new Order(Integer.parseInt(inputNum), inputPeople, inputTel, LocalDate.now().toString(), "", "");
                        JOptionPane.showMessageDialog(null, "入库成功");
                        return;
                    }
                }
            }
        });
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                return;
            }
        });

    }
}
